﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace simple_tools
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void ToUpper(object sender, EventArgs e)
        {
            string text = richTextBox1.Text;
            richTextBox1.Text = text.ToUpper();
            //labelLength();
        }

        private void ToLower(object sender, EventArgs e)
        {
            string text = richTextBox1.Text;
            richTextBox1.Text = text.ToLower();
            //labelLength();
        }

        private void SmallCamel(object sender, EventArgs e)
        {
            richTextBox1.Text = Camel(richTextBox1.Text, "small");
            //labelLength();
        }


        private string Camel(string text, string bigOrSmall)
        {
            if (text != null && !text.Trim().Equals(""))
            {
                bool flag = false;
                StringBuilder stringBuilder = new StringBuilder();
                char[] chars = { ' ', '\n', '\t', '\r', ',', '(', ')', '\"', '\'', '.', '?', '!', '<', '>',
                    '{', '}', '，', '。', '、', '（', '）', '《', '》', '{', '}', '-', '”', '“', '\'',
                '/','\\'};
                List<Char> list = chars.ToList<Char>();
                char[] txtCount = text.ToCharArray();
                if (txtCount.Length > 0)
                {
                    for (int i = 0; i < txtCount.Length; i++)
                    {
                        char temp = txtCount[i];
                        if (temp == '_')
                        {
                            flag = true;
                        }
                        else
                        {
                            if (list.Contains(temp))
                            {

                                if (bigOrSmall.Equals("samll"))
                                {
                                    flag = false;
                                }

                                if (bigOrSmall.Equals("big"))
                                {
                                    flag = true;
                                }
                                stringBuilder.Append(temp);
                                continue;
                            }
                            string newTemp = temp + "";
                            if (flag)
                            {
                                stringBuilder.Append(newTemp.ToUpper());
                                flag = false;
                            }
                            else
                            {
                                stringBuilder.Append(newTemp.ToLower());
                            }

                        }
                    }

                }
                return stringBuilder.ToString();

            }
            else { return text; }
        }

        private void BigCamel(object sender, EventArgs e)
        {
            string temp = Camel(richTextBox1.Text, "big");
            if (temp.Length > 0)
            {
                temp = temp.Substring(0, 1).ToUpper() + temp.Substring(1);
            }
            richTextBox1.Text = temp;
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            LabelLength();
        }

        private void LabelLength()
        {
            int length = richTextBox1.Text.Length;
            label1.Text = length.ToString();
        }

        private void WordCount(object sender, EventArgs e)
        {

        }

        private void AddSyh(object sender, EventArgs e)
        {
            string temp = richTextBox1.Text.Trim();
            if (!temp.Contains("\n"))
            {
                richTextBox1.Text = "\"" + temp + "\"";
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                List<string> list = temp.Split('\n').ToList();
                int count = list.Count();
                for (int i = 0; i < count; i++)
                {
                    sb.Append("\"").Append(list[i]).Append("\"");
                    if (i != count - 1)
                    {
                        sb.Append(",\n");
                    }
                }
                richTextBox1.Text = sb.ToString();
            }
        }
    }

}
